// 引入所需的库  
import JSEncrypt from 'jsencrypt';  
import CryptoJS from 'crypto-js';  
  
// 使用JSEncrypt加密数据（通常用于加密少量数据或密钥）  
export function encryptWithRSA(data) {  
    const encrypt = new JSEncrypt();  
    const publicKey = `-----BEGIN PUBLIC KEY-----  
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhUPT1iOOITbQF/qjmJXI7p9hbd+yqmp98+6IfEewsuE2/27vDGI08l9Q+jyEonAcbA/Q1cShxbeA9vmmdygpbhh/Z5ZFtHfCK3wC69P9eZQJmjK5PR490xhicaOntjBunNA6Fifre1JXgKeeTTB7YgDsT98dZHPXdxSIM4uxRnUwqlmkR6UFlcVOYwA1q6FMsWQmHbPmc0UjS6j8lSr/DkQxpgkz1mtLuU7k41x2uVqt54u83uqj4qo3nNZHIhmouNzFBnqfMAXQtjXLUWf2tjj9Ui5Hrct1W2yTQu3r1v6LMsH7yKhkObQzG/xWn6O4Fn7Uv7dVt+F6ciQ7kQzZ6wIDAQAB  
-----END PUBLIC KEY-----`;  
    encrypt.setPublicKey(publicKey);  
    return encrypt.encrypt(data);  
}  
  
// 使用CryptoJS进行AES加密  
export function encryptWithAES(data, secretKey, iv) {  
    const secretKeys = CryptoJS.enc.Utf8.parse(secretKey);  
    const ivs = CryptoJS.enc.Utf8.parse(iv);  
    return CryptoJS.AES.encrypt(data, secretKeys, {  
        iv: ivs,  
        mode: CryptoJS.mode.CBC,  
        padding: CryptoJS.pad.Pkcs7  
    }).toString();  
}